
<?php 
	include ("config.php");
	$sql_menu = mysql_query("SELECT m.id,m.menu,m.caminho FROM tbl_menu m  WHERE m.view = 'A' AND m.disposicao = ''   ORDER BY m.ordem ASC");
?>
<ul class="menu">
<?php while(list($id,$menu,$caminho)=mysql_fetch_array($sql_menu)){ ?>
		<li>
        <?php 
		/*consulta os itens de menu se tiver*/
		$sql_Itens = mysql_query("SELECT id,id_menu,nome,link FROM tbl_itens WHERE id_menu = '".$id."'");
		$sql_Itens_t = mysql_num_rows($sql_Itens);/*verifica se tem dados referente aquele menu*/
		
		if($caminho != ""){
			$link_menu = $caminho;
		}else{
			$link_menu = "";
		}
		if($sql_Itens_t > 0){
			$parent = "class=\"parent\"";
		}else{
			$parent = "";
		}
		?>
        <a <?php echo $parent;?> onclick="tp();" href="<?php echo $link_menu; ?>"><span><?php echo $menu; ?></span></a>
        <?php 
		
		if($sql_Itens_t > 0){
		echo "<div><ul>";
			while(list($id_iten,$id_menu,$nome,$link)=mysql_fetch_array($sql_Itens)){
				
			$sql_sub_itens = mysql_query("SELECT * FROM tbl_subitens WHERE cod_itens = '$id_iten'");
			$sql_sub_itens_rows = mysql_num_rows($sql_sub_itens);

			if($sql_sub_itens_rows > 0){
				$parent = "class=\"parent\"";
			}else{
				$parent = "";
			}
				
			if($id_menu == '27'){
				$caminho = $link;
				
			}else if($id_iten == '53'){
				$caminho = 'internas&exibir=contas.php&ID=4';	
			}else if($link == 'doc'){
				$caminho = 'internas&exibir=docs.php&IDITEM='.$id_iten;
			}else if ($link == 'noticia'){
				$caminho = 'noticia';
			}else{
				$caminho = 'internas&exibir=secoes.php&ID='.$id_iten;			
			}
		?>
			<li><a <?php echo $parent;?> href="<?php echo $caminho; ?>"><span><?php echo $nome?></span></a>
            <?php if($sql_sub_itens_rows > 0){ ?>
            <div>
            	<ul>
            <?php while($dados_sub = mysql_fetch_object($sql_sub_itens)){?>    
            		<li><a href="internas&exibir=secoes.php&IDITEM=<?php echo $dados_sub->codigo; ?>" ><span><?php echo $dados_sub->nome;?></span></a></li>
             <?php }?>       
            	</ul>
            </div>
            <?php } ?>
            </li>
            
	        <?php }
		echo "</ul></div>"; ?>
		<?php 
		}else{
			echo "</li>";		
		}
		?>
<?php } ?>
</ul>
